package kr.co.sdworld.api.apns.repository.app;

import java.util.List;
import java.util.Map;

import kr.co.sdworld.api.apns.model.ApnsApp;
import kr.co.sdworld.api.apns.model.base.Model;
import kr.co.sdworld.api.apns.model.mapper.ApnsAppMapper;
import kr.co.sdworld.api.apns.model.mapper.ApnsAppMapperCustom;
import kr.co.sdworld.api.apns.repository.WhereCondition;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class ApnsAppDaoImpl extends SqlSessionDaoSupport implements ApnsAppDao
{
	@Override
	public ApnsApp getApnsApp(String appId) 
	{
		ApnsAppMapper mapper = getSqlSession().getMapper(ApnsAppMapper.class);
		return mapper.selectByPrimaryKey(appId);
	}
	
	@Override
	public int create(ApnsApp apnsApp) 
	{
		ApnsAppMapper mapper = getSqlSession().getMapper(ApnsAppMapper.class);
		return mapper.insertSelective(apnsApp);
	}
	
	@Override
	public List<Model> search(WhereCondition whereCondition) 
	{
		ApnsAppMapperCustom mapper = getSqlSession().getMapper(ApnsAppMapperCustom.class);
		List<Model> result = mapper.selectList(whereCondition.toParamMap());
		return result;
	}
	
	@Override
	public List<Model> search(int startNum, int endNum, WhereCondition whereCondition) {
		Map<String,Object> param = whereCondition.toParamMap();
		param.put("startNum", startNum);
		param.put("endNum", endNum);
		
		ApnsAppMapperCustom mapper = getSqlSession().getMapper(ApnsAppMapperCustom.class);
		List<Model> result = mapper.selectList(param);
		return result;
	}
	
	@Override
	public int searchCount(WhereCondition whereCondition) 
	{
		ApnsAppMapperCustom mapper = getSqlSession().getMapper(ApnsAppMapperCustom.class);
		return mapper.selectCount(whereCondition.toParamMap());
	}
	
	@Override
	public int delete(String appId)
	{
		ApnsAppMapper mapper = getSqlSession().getMapper(ApnsAppMapper.class);
		return mapper.deleteByPrimaryKey( appId);
	}
}
